// To parse this JSON data, do
//
//     final quizRecordData = quizRecordDataFromJson(jsonString);

import 'dart:convert';

import 'package:ichinesereader/models/book/BookQuiz.dart';

QuizRecordData quizRecordDataFromJson(String str) =>
    QuizRecordData.fromJson(json.decode(str));

String quizRecordDataToJson(QuizRecordData data) => json.encode(data.toJson());

class QuizRecordData {
  QuizRecordData({
    this.quiz,
    this.simpleAnswerKey,
    this.tradAnswerKey,
    this.answers,
  });

  BookQuiz? quiz;
  Map<String, List<String>>? simpleAnswerKey;
  Map<String, List<String>>? tradAnswerKey;
  List<QuizRecordDataAnswer>? answers;

  factory QuizRecordData.fromJson(Map<String, dynamic> json) => QuizRecordData(
        quiz: BookQuiz.fromJson(json["quiz"]),
        simpleAnswerKey: Map.from(json["simpleAnswerKey"]).map((k, v) =>
            MapEntry<String, List<String>>(
                k, List<String>.from(v.map((x) => x)))),
        tradAnswerKey: Map.from(json["tradAnswerKey"]).map((k, v) =>
            MapEntry<String, List<String>>(
                k, List<String>.from(v.map((x) => x)))),
        answers: List<QuizRecordDataAnswer>.from(
            json["answers"].map((x) => QuizRecordDataAnswer.fromJson(x))),
      );

  Map<String, dynamic> toJson() => {
        "quiz": quiz != null ? bookQuizToJson(quiz!) : null,
        "simpleAnswerKey": simpleAnswerKey != null
            ? Map.from(simpleAnswerKey!).map((k, v) =>
                MapEntry<String, dynamic>(
                    k, List<dynamic>.from(v.map((x) => x))))
            : null,
        "tradAnswerKey": tradAnswerKey != null
            ? Map.from(tradAnswerKey!).map((k, v) => MapEntry<String, dynamic>(
                k, List<dynamic>.from(v.map((x) => x))))
            : null,
        "answers": answers != null
            ? List<dynamic>.from(answers!.map((x) => x.toJson()))
            : null,
      };
}

class QuizRecordDataAnswer {
  QuizRecordDataAnswer({
    this.simple,
    this.when,
    this.score,
    this.gradedAnswers,
    this.submittedAnswers,
  });

  bool? simple;
  int? when;
  int? score;
  Map<String, bool>? gradedAnswers;
  Map<String, List<String>>? submittedAnswers;

  factory QuizRecordDataAnswer.fromJson(Map<String, dynamic> json) =>
      QuizRecordDataAnswer(
        simple: json["simple"],
        when: json["when"],
        score: json["score"],
        gradedAnswers: Map.from(json["gradedAnswers"])
            .map((k, v) => MapEntry<String, bool>(k, v)),
        submittedAnswers: Map.from(json["submittedAnswers"]).map((k, v) =>
            MapEntry<String, List<String>>(
                k, List<String>.from(v.map((x) => x)))),
      );

  Map<String, dynamic> toJson() => {
        "simple": simple,
        "when": when,
        "score": score,
        "gradedAnswers": gradedAnswers != null
            ? Map.from(gradedAnswers!)
                .map((k, v) => MapEntry<String, dynamic>(k, v))
            : null,
        "submittedAnswers": submittedAnswers != null
            ? Map.from(submittedAnswers!).map((k, v) =>
                MapEntry<String, dynamic>(
                    k, List<dynamic>.from(v.map((x) => x))))
            : null,
      };
}
